﻿<cfsilent>
	<cfscript>

		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		
		teacherId = sessionAdvice.getAutherUserID();
		
		hashCode = event.getArg("Sign");
		taskId = event.getArg("TSK");
		taskType = event.getArg("TT");
		
		checked = false;
		
		try {
			
			if ( decrypt(hashCode, teacherId, "PBEWithMD5AndDES", "Hex") eq taskId ) {
				
				checked = true;
				
				/* 载入补考教学任务 */
				sql="SELECT 
							c.course_name,a.cidx,b.academic_year,b.academic_term 
					 FROM   t_resitplan a 
                			INNER JOIN t_term b ON a.term_id=b.term_id 
                  			INNER JOIN t_course c ON a.cid = c.cid 
     				 WHERE  a.task_id=:taskId ";
					 
				queryObj = new Query( datasource=application.dnsSlave ); 
				
				queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
				
				rs_task = queryObj.execute( sql=sql ).getResult();
				
				/* 载入成绩提交名单 */
				sql="SELECT b.stu_id,b.stu_name,c.cls_name,
							c.grade,d.sbj_name,e.institute_name,
      					    a.retaking 
					 FROM t_temp_mark_resit a 
						  INNER JOIN t_student b ON a.stu_id=b.stu_id 
						  INNER JOIN t_class c ON b.cls_id = c.cls_id 
						  INNER JOIN t_subject d ON c.sbj_id = d.sbj_id 
						  INNER JOIN t_institute e ON d.institute_id = e.institute_id 
						  INNER JOIN t_resitplan f ON a.task_id=f.task_id
					 WHERE f.task_id =:taskId  
          			 ORDER BY b.stu_id ";
					 
				queryObj = new Query( datasource=application.dnsSlave ); 
				
				queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
				
				rs_student = queryObj.execute( sql=sql ).getResult();
				
				temFile = GetTempDirectory() & createUUID() & ".xls";
				downFile = URLEncodedFormat(rs_task.course_name & "," & rs_task.cidx & "," & rs_task.academic_year & "-" & rs_task.academic_term & ",补考成绩名单", "utf-8");
				
				excel = getProperty("serviceFactory").getBean("spreadSheetObject");
		
				/* 创建工作簿 */
				spreadsheetObj = excel.SpreadSheetNew("补考成绩名单", false);
		
				/* 添加表头 */
				excel.SpreadsheetAddrow(spreadsheetObj, "学号,姓名,班级,年级,专业,学院,是否重修,补考成绩");
				
				row = 1;
		
					for( a=1; a LTE rs_student.recordCount; a++ ){
					row++;
			
					/* 构建选课数据 */
					rowData = rs_student["stu_id"][a]
							& "," & rs_student["stu_name"][a]
							& "," & rs_student["cls_name"][a]
							& "," & rs_student["grade"][a]
							& "," & rs_student["sbj_name"][a]
							& "," & rs_student["institute_name"][a]
							& "," & dictAdvice.getBoolean(rs_student["retaking"][a]);
			
					/* 写入选课信息 */
					excel.SpreadsheetAddrow(spreadsheetObj, rowData);
				}
		
				excel.SpreadSheetWrite(spreadsheetObj, temFile, true);
				
			}
			
		}
		catch (any ecpt) {
		}
		
	
	</cfscript>
	
	<cfif checked >
		<cfheader name="Content-Disposition" value="attachment; filename=#downFile#.xls" />
		<cfcontent file="#temFile#" reset="yes" type="application/msexcel" deletefile="yes" />	
	</cfif>	
	
</cfsilent>